from Myreadfile import Myreadfile


class QAPModel():
    N = 0
    A = []
    B = []

    def __init__(self, path="./Nugent15/data/nug15.dat"):
        self.file = Myreadfile(path)
        # print(self.file.N)    # 节点数量，在Myreadfile中已经测试过
        self.N = self.file.N
        self.A = self.file.A
        self.B = self.file.B
        # self.val([1, 2, 3])  #此处快捷测试val函数

    def val(self, p):
        # 验证完毕
        dict_x = dict()
        index = 1
        for i in p:
            dict_x[index] = i
            index += 1
        ans = 0
        for i in dict_x.keys():
            for j in dict_x.keys():
                ans += self.file.A[i-1, j-1] * \
                    self.file.B[dict_x[i]-1, dict_x[j]-1]
        # print(ans)
        return ans
